package com.myFirstSpringBootDemo.demo.pojo;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Email;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ConfigurationProperties 将配置文件中的每一个属性的值，映射到这个组件中
 * 将本类中所有的属性和配置文件中的相关配置进行绑定
 * prefix = "person" 配置文件中哪一个下面的所有属性进行一一映射
 * @Component 只有这个组件是容器中的组件，才能提供@ConfigurationProperties的功能
 * 添加这个坐标才不会有错误提示（在yml里提示person，要运行过一次才会有提示），有没有这个坐标都不影响使用
 * <dependency>
 * <groupId>org.springframework.boot</groupId>
 * <artifactId>spring-boot-configuration-processor</artifactId>
 * </dependency>
 */
@Component("person1")
@ConfigurationProperties(prefix = "person")
@Validated  //@ConfigurationProperties 注解支持数据JSR303文档校验，@Value 不支持
public class Person {

    private String name;

    private Integer age;

    private List<String> friendList;

    private Map<String, String> map;

    private Date birthday;

    private Dog dog;

    @Email
    private String email;



    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", friendList=" + friendList +
                ", map=" + map +
                ", birthday=" + birthday +
                ", dog=" + dog +
                ", email='" + email + '\'' +
                '}';
    }
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public List<String> getFriendList() {
        return friendList;
    }

    public void setFriendList(List<String> friendList) {
        this.friendList = friendList;
    }

    public Map<String, String> getMap() {
        return map;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }
}
